package app.fugema.shop.main.goods.adapter;

import com.base.common.model.bean.ADInfo;
import com.base.common.utils.DensityUtil;
import com.base.common.utils.span.SpanUtils;
import com.base.common.view.adapter.MyLinearLayoutManager;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.ada.SingleRecyclerAdapter;
import com.base.common.view.adapter.bean.HeaderBean;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseViewHolder;
import app.fugema.shop.R;
import app.fugema.shop.databinding.SeckillPrecinctTopSpecialOfferBinding;
import app.fugema.shop.databinding.SeckillPrecinctTopSpecialOfferItemBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * 每日特价
 */
public class SeckillPrecinctTopSpecialOfferItemMultiType extends BaseItemMultiType<HeaderBean, SeckillPrecinctTopSpecialOfferBinding> {


    @Override
    public int getLayoutId() {
        return R.layout.seckill_precinct_top_special_offer;
    }


    @Override
    public int getItemViewType() {
        return TYPE_HEAD;
    }

    @Override
    public void onCreateViewHolder(SeckillPrecinctTopSpecialOfferBinding binding, BaseViewHolder viewHolder) {
        super.onCreateViewHolder(binding, viewHolder);
        binding.rvRecyclerView.setLayoutManager(new MyLinearLayoutManager(viewHolder.itemView.getContext(), 0, false));
        binding.rvRecyclerView.setAdapter(new SingleRecyclerAdapter<ADInfo, SeckillPrecinctTopSpecialOfferItemBinding>() {
            @Override
            public int getLayoutId() {
                return R.layout.seckill_precinct_top_special_offer_item;
            }

            @Override
            public void onBindViewHolder(SeckillPrecinctTopSpecialOfferItemBinding binding, int position, ADInfo bean) {
                super.onBindViewHolder(binding, position, bean);
                SpanUtils.with(binding.tvPrice).append("￥").setFontSize(DensityUtil.getDimens(R.dimen.font_9))
                        .append(bean.getImageName()).create();
            }
        });

    }

    @Override
    public void onBindViewHolder(SeckillPrecinctTopSpecialOfferBinding binding, int position, BaseViewHolder viewHolder, HeaderBean bean) {
        super.onBindViewHolder(binding, position, viewHolder, bean);
        if (binding.rvRecyclerView.getAdapter() instanceof BaseRVAdapter) {
            BaseRVAdapter rvAdapter = (BaseRVAdapter) binding.rvRecyclerView.getAdapter();

            List<ADInfo> list = new ArrayList<>();

            ADInfo adInfo1 = new ADInfo();
            adInfo1.setImageName("52.0");
            adInfo1.setCount(0);
            list.add(adInfo1);

            ADInfo adInfo2 = new ADInfo();
            adInfo2.setImageName("520.0");
            adInfo2.setCount(1);
            list.add(adInfo2);

            ADInfo adInfo3 = new ADInfo();
            adInfo3.setImageName("380.0");
            adInfo3.setCount(2);
            list.add(adInfo3);

            rvAdapter.setDataList(list);
        }
    }
}
